* plot average game scores by plays ("learning curves")

***Inputs: 
* $Data/GameUserWPdaily_norm.dta
* $Data/maxmindirectionsmonth_zip260.dta


***Ouputs: 
* $Results/agelearning_detail.png
* $Results/agelearning_oldyoungci.png



	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)

		
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360

	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection==.
	
	keep if maxzipwind<. 
	
	
		egen cut_temp = cut(weighted_temperature), at(-40(10)40)

	
label variable highpm "Daily PM2.5 $>$ 25" 
	



	
 egen cut_age = cut(age_sig), at(20(10)81)

 replace cut_age = 70 if age> =80
 replace cut_age = 20 if age<20
 
 label variable norm_score "Standardized Score"
 
 
 forval age = 20(10)70 {

	
	reg norm_score i.nth_play if cut_age== `age' 
	
	margins nth_play, saving($Results/file`age') 
	
	
	
 }
 
 	 
	 
	 combomarginsplot $Results/file20 $Results/file30  $Results/file40  $Results/file50  $Results/file60  $Results/file70 	 , labels(  "<30" ///
			  "30" ///
			  "40" ///
			   "50" ///
			   "60"  ///
			   "{&ge}70") ///
	 file1opts(color(red%30)   msymbol(O) msize(small) lpattern(solid) ) file2opts(color(orange%30)   msymbol(O) msize(small) lpattern(solid)) file3opts(color(gold%30)  msymbol(O) msize(small) lpattern(solid)) file4opts(color(green%30)  msymbol(O) msize(small) lpattern(solid)) file5opts(color(blue%30)  msymbol(O) msize(small) lpattern(solid)) file6opts(color("111 000 255 %30")  msymbol(O) msize(small) lpattern(solid))  ci1opts(color(red%30) lstyle(none)) ci2opts(color(orange%30) lstyle(none))  ci3opts(color(gold%30) lstyle(none))  ci4opts(color(green%30) lstyle(none))  ci5opts(color(blue%30) lstyle(none))  ci6opts(color("111 000 255 %30") lstyle(none))  recastci(rarea) ///
	 ytitle("Standardized Score") title(" ") legend(title("Age:", size(small)) rows(1) bmargin(zero) region(lstyle(none))) yscale(range(-1.5 2.5))
	
	graph export $Results/agelearning_detail.png, replace
	

	

	
	gen above50 = age_sig >= 50 & age_si<.
	
	
	
	
	reg norm_score i.nth_play if above50 == 0 
	
	margins nth_play, saving($Results/fileyoung) 
	
	
	
	reg norm_score i.nth_play if above50 == 1
	
	margins nth_play, saving($Results/fileold) 
	
	
	
	
	 combomarginsplot $Results/fileyoung $Results/fileold  , labels( "Age < 50"  "Age {&ge}50") ///
	 file1opts(color(red%30)   msymbol(O) msize(small) lpattern(solid) ) file2opts(color(orange%30)   msymbol(O) msize(small) lpattern(solid)) ci1opts(color(red%30) lstyle(solid) lcolor(red%30)) ci2opts(color(orange%30) lstyle(solid) lcolor(orange%30) )   recastci(rarea) ///
	 ytitle("Standardized Score") title(" ") legend(rows(1) bmargin(zero) region(lstyle(none)))
	
	graph export $Results/agelearning_oldyoungci.png, replace
	
	
	
